package com.dpj.entity;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Account {

	private String AcCategory;
	private String AccountId;
	private String AcDate;
	private String AcGroupID;
	private String AcKeyIn;
	private String AcTypeID;
	private String Amount;
	private String InvoiceNo;
	private String InvoiceYM;
	private String Memo;
	private String StoreName;
	public String getAcCategory() {
		return AcCategory;
	}
	public void setAcCategory(String acCategory) {
		AcCategory = acCategory;
	}
	public String getAccountId() {
		return AccountId;
	}
	public void setAccountId(String accountId) {
		AccountId = accountId;
	}
	public String getAcDate() {
		return AcDate;
	}
	public void setAcDate(String acDate) {
		AcDate = acDate;
	}
	public String getAcGroupID() {
		return AcGroupID;
	}
	public void setAcGroupID(String acGroupID) {
		AcGroupID = acGroupID;
	}
	public String getAcKeyIn() {
		return AcKeyIn;
	}
	public void setAcKeyIn(String acKeyIn) {
		AcKeyIn = acKeyIn;
	}
	public String getAcTypeID() {
		return AcTypeID;
	}
	public void setAcTypeID(String acTypeID) {
		AcTypeID = acTypeID;
	}
	public String getAmount() {
		return Amount;
	}
	public void setAmount(String amount) {
		Amount = amount;
	}
	public String getInvoiceNo() {
		return InvoiceNo;
	}
	public void setInvoiceNo(String invoiceNo) {
		InvoiceNo = invoiceNo;
	}
	public String getInvoiceYM() {
		return InvoiceYM;
	}
	public void setInvoiceYM(String invoiceYM) {
		InvoiceYM = invoiceYM;
	}
	public String getMemo() {
		return Memo;
	}
	public void setMemo(String memo) {
		Memo = memo;
	}
	public String getStoreName() {
		return StoreName;
	}
	public void setStoreName(String storeName) {
		StoreName = storeName;
	}
	
	public static List<Account> getAccountList(String json) {
		List<Account> list = new ArrayList<Account>();
		try {
			JSONArray ja = new JSONArray(json);
			if(ja != null) {
				for(int i = 0; i < ja.length(); i++) {
					JSONObject jo = ja.optJSONObject(i);
					JSONObject jo_app = jo.optJSONObject("APP");
					JSONObject jo_acc = jo_app.optJSONObject("ArrayOfAccount");
					if(jo_acc != null) {
						JSONArray ja_acc = jo_acc.optJSONArray("Account");
						if(ja_acc != null) {
							for(int j = 0; j < ja_acc.length(); j++) {
								JSONObject jac = ja_acc.optJSONObject(j);
								Account account = new Account();
								account.setAcCategory(jac.optString("AcCategory"));
								account.setAccountId(jac.optString("AccountId"));
								account.setAcDate(jac.optString("AcDate"));
								account.setAcGroupID(jac.optString("AcGroupID"));
								account.setAcKeyIn(jac.optString("AcKeyIn"));
								account.setAcTypeID(jac.optString("AcTypeID"));
								account.setAmount(jac.optString("Amount"));
								account.setInvoiceNo(jac.optString("InvoiceNo"));
								account.setInvoiceYM(jac.optString("InvoiceYM"));
								account.setMemo(jac.optString("Memo"));
								account.setStoreName(jac.optString("StoreName"));
								list.add(account);
							}
						} else {
							JSONObject jo_one = jo_acc.optJSONObject("Account");
							Account account_one = new Account();
							account_one.setAcCategory(jo_one.optString("AcCategory"));
							account_one.setAccountId(jo_one.optString("AccountId"));
							account_one.setAcDate(jo_one.optString("AcDate"));
							account_one.setAcGroupID(jo_one.optString("AcGroupID"));
							account_one.setAcKeyIn(jo_one.optString("AcKeyIn"));
							account_one.setAcTypeID(jo_one.optString("AcTypeID"));
							account_one.setAmount(jo_one.optString("Amount"));
							account_one.setInvoiceNo(jo_one.optString("InvoiceNo"));
							account_one.setInvoiceYM(jo_one.optString("InvoiceYM"));
							account_one.setMemo(jo_one.optString("Memo"));
							account_one.setStoreName(jo_one.optString("StoreName"));
							list.add(account_one);
						}
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}
	
}
